package open.panxiong.shared.activity.screen

//import android.Manifest
//import android.annotation.SuppressLint
//import android.content.Context
//import android.content.pm.PackageManager
//import android.net.ConnectivityManager
//import android.net.ConnectivityManager.NetworkCallback
//import android.net.NetworkCapabilities
//import android.net.NetworkRequest
//import android.net.wifi.WifiNetworkSpecifier
//import android.os.Build
//import android.util.Log
//import androidx.activity.compose.rememberLauncherForActivityResult
//import androidx.activity.result.contract.ActivityResultContracts
//import androidx.annotation.RequiresApi
//import androidx.compose.foundation.layout.Column
//import androidx.compose.foundation.layout.padding
//import androidx.compose.material3.Button
//import androidx.compose.material3.Scaffold
//import androidx.compose.material3.Text
//import androidx.compose.runtime.Composable
//import androidx.compose.runtime.mutableStateOf
//import androidx.compose.runtime.remember
//import androidx.compose.runtime.rememberCoroutineScope
//import androidx.compose.ui.Modifier
//import androidx.compose.ui.platform.LocalContext
//import kotlinx.coroutines.launch
//import open.panxiong.shared.activity.router.Router
//
//
////@RequiresApi(Build.VERSION_CODES.Q)
//val REQUEST_PERMISSION_LIST = listOf(
////    Manifest.permission.ACCESS_BACKGROUND_LOCATION,
//    Manifest.permission.WRITE_SETTINGS,
//    Manifest.permission.CHANGE_NETWORK_STATE,
//    Manifest.permission.ACCESS_FINE_LOCATION,
//    Manifest.permission.ACCESS_COARSE_LOCATION,
//)
//
//@SuppressLint("CoroutineCreationDuringComposition")
//@RequiresApi(Build.VERSION_CODES.Q)
//@Composable
//fun HotspotScreen(router: Router) {
//    val context = LocalContext.current
//    val scope = rememberCoroutineScope()
//
//    val permissionState = remember { mutableStateOf(false) }
//    val requestPermissionList = remember { mutableListOf<String>() }
//    for (permission in REQUEST_PERMISSION_LIST) {
//        if (context.checkSelfPermission(permission) != PackageManager.PERMISSION_GRANTED) {
//            requestPermissionList.add(permission)
//        }
//    }
//    val activityResult = rememberLauncherForActivityResult(
//        contract = ActivityResultContracts.RequestMultiplePermissions(),
//        onResult = { isGrantedMap ->
//            Log.e("权限", isGrantedMap.toString())
//            requestPermissionList.clear()
//            isGrantedMap.entries.forEach {
//                if (!it.value) requestPermissionList.add(it.key)
//            }
//            permissionState.value = requestPermissionList.isEmpty()
//        }
//    )
//    if (requestPermissionList.isNotEmpty()) {
//        scope.launch {
//            activityResult.launch(requestPermissionList.toTypedArray())
//        }
//    }
//
//    Scaffold { pv ->
//        Column(modifier = Modifier.padding(pv)) {
//            if (permissionState.value) {
//                Button(onClick = {
//                    turnOnHotspot(context)
//                }) {
//                    Text(text = "开启热点")
//                }
//            } else {
//                Text(text = "必要权限没有获得无法开启热点网络")
//            }
//        }
//    }
//
//}
//
//@RequiresApi(Build.VERSION_CODES.Q)
//private fun turnOnHotspot(context: Context) {
//    val wifiNetworkSpecifier = WifiNetworkSpecifier.Builder()
//        .setSsid("myssid")
//        .setWpa2Passphrase("12345678")
//        .build()
//    val networkRequest = NetworkRequest.Builder()
//        .addTransportType(NetworkCapabilities.TRANSPORT_WIFI)
//        .setNetworkSpecifier(wifiNetworkSpecifier)
//        .build()
//    val connectivityManager = context
//        .getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager?
//    connectivityManager!!.requestNetwork(networkRequest, NetworkCallback())
//}